#!/bin/bash

# 导出目录 mysql -h192.168.0.26 -u root -pgni2PbgxMNutdxz
EXPORT_DIR="/home/mysql"

# 获取以 "scf" 开头的表名列表
TABLES=$(mysql -h192.168.0.26 -uroot -pgni2PbgxMNutdxz -P3306 -e "SELECT table_name FROM information_schema.tables  WHERE   table_name LIKE 'scf%' ;" | tail -n +2)

# 循环导出每个表
for table in $TABLES; do
    sleep 3
    echo "导出表名字=== table: $table"
    mysqldump   -h192.168.0.26 -uroot -pgni2PbgxMNutdxz -P3306  scm_prod  "$table" > "$EXPORT_DIR/$table.sql"
    if [ $? -eq 0 ]; then
        echo "导出 table $table 成功"
    else
        echo "失败 to export table $table"
    fi
done
